<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:include page="../common.jsp"/>
<body>
<div id="wrap">
  <div id="top_content">
    <jsp:include page="../head.jsp"/>
    <div id="content">
      <p id="whereami">
      </p>
      <h1>
        Welcome!
      </h1>
      <div style="">
        <script>
          var fileType =[".jpg","gif"];

          function selectFile(){
            //触发 文件选择的click事件
            $("#file").trigger("click");
          }
          function uploadFile(target) {
            //alert(1);
            var fileSize = target.files[0].size;
            var size = fileSize / 1024 / 1024;
            if (size > 1) {
              alert("文件不能大于1M");
              return;
            }
//            var yesNo = false;
//            var filePath = target.value;
//            var suffix = filePath.substring(filePath.indexOf("."));
//            if (fileType && fileType.length>0) {
//              for (var i = 0; i < fileType.length; i++) {
//                if (fileType[i] == suffix) {
//                  yesNo = true;
//                  break;
//                }
//              }
//            }
//            if (!yesNo) {
//              alert("不支持该格式文件");
//              return;
//            }
            $("#uploadForm").ajaxSubmit({
              type : 'post',
              url : "${base}/user/uploadFile",
              //data:  //注意只要是写在表单里面的，都不需要加这个属性。在controller中可以根据@RequestParam String str获取到属性值。
              contentType : "application/x-www-form-urlencoded; charset=utf-8",
              success: function(data) {
                if(data == "success"){
                  //var obj = JSON.parse(data);
                  //alert(data);
                  alert("上传成功");
                  var imgSrc = $("#img").attr("src");
                  $("#img").attr("src", imgSrc + "&" + Math.random());
                }else{
                  alert("上传失败");
                }
              },
              error: function (data)
              {
                alert("error");
              }
            });
          }
        </script>
        <img id="img" src="${base}/user/getImage?userId=${sessionScope.currentUser.userId}" height="50" width="50">
        <form  id="uploadForm" enctype="multipart/form-data">
          <input type="file" id="file" name="file" onchange="uploadFile(this)" accept=".png,.jpg" style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;"/>
        <input type="button" class="button" value="选择" onclick="selectFile();"/>
        <input type="hidden" name="userId" value="${sessionScope.currentUser.userId}"/>
        </form>
      </div>
      <table class="table">
        <tr class="table_header">
          <td>
            userId
          </td>
          <td>
            userName
          </td>
          <td>
            nickName
          </td>
          <td>
            lastLoginTime
          </td>
          <td>
            brith
          </td>
          <td>
            dataStatus
          </td>
          <td>
            oper
          </td>
        </tr>
        <c:forEach items="${userList}" var="user" varStatus="i">
        <tr class="row${i.index % 2 + 1}">
          <td>
            ${user.userId}
          </td>
          <td>
            ${user.userName}
          </td>
          <td>
            ${user.nickName}
          </td>
          <td>
            <fmt:formatDate value="${user.lastLoginTime}" pattern="yyyy年MM月dd日 HH:mm:ss"/>
          </td>
          <td>
            <fmt:formatDate value="${user.brith}" pattern="yyyy年MM月dd日 HH:mm:ss"/>

          </td>
          <td>
            <c:choose>
              <c:when test="${user.dataStatus == 0}">否</c:when>
              <c:when test="${user.dataStatus == 1}">是</c:when>
            </c:choose>
          </td>
          <td>
            <a href="${base}/user/deleteUser?userId=${user.userId}">删除</a>&nbsp;
            <a href="${base}/user/updateUserView?userId=${user.userId}">修改</a>&nbsp;
            <a href="${base}/user/queryLoginLog?userId=${user.userId}">查看</a>
          </td>
        </tr>
        </c:forEach>
      </table>
      <p>
        <input type="button" class="button" value="新增" onclick="javascript:window.location.href='${base}/user/addUserView'"/>
      </p>
    </div>
  </div>
<jsp:include page="../foot.jsp"/>
</div>
</body>
</html>
